package pl.enigmatic.time;

/**
 * Describes how a timeline repeats its simple duration.
 * @author reggie_7
 * @see <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.animation.repeatbehavior.aspx">msdn reference</a>
 */
public final class RepeatBehavior {

	public static final RepeatBehavior FOREVER = new RepeatBehavior(Type.FOREVER, 0.0);

	public static RepeatBehavior createDuration(final double seconds) {
		return new RepeatBehavior(Type.DURATION, seconds);
	}

	public static RepeatBehavior createCount(final double times) {
		return new RepeatBehavior(Type.COUNT, times);
	}

	public static enum Type {
		COUNT, DURATION, FOREVER
	}

	/** the type of this repeat behavior */
	private final Type type;
	/** the meaning of this value depends on type */
	private final double value;

	private RepeatBehavior(final Type type, final double value) {
		this.type = type;
		this.value = value;
	}

	public boolean isForever() {
		return type == Type.FOREVER;
	}

	public boolean hasCount() {
		return type == Type.COUNT;
	}

	public boolean hasDuration() {
		return type == Type.DURATION;
	}

	/** @return the number of times a timeline should repeat */
	public double getCount() {
		return hasCount() ? value : 0.0;
	}

	public double getDuration() {
		return hasDuration() ? value : 0.0;
	}

	@Override
	public String toString() {
		return getClass().getSimpleName() + " [" + (type != null ? "type=" + type + ", " : "") + "value=" + value + "]";
	}

}